<template>
	<!-- 带压参数计算软件 -->
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350" :label-position="labelPosition" label="井内管柱外径 (mm)" prop="f1">
				<u-input :border="border" placeholder="井内管柱外径 " v-model="model.f1" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="井口压力 (MPa)" prop="g1">
				<u-input :border="border" placeholder="井口压力 " v-model="model.g1" type="digit"></u-input>
			</u-form-item>

		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>

				<view>
					作用在管柱上的截面力的值为：<span v-if="model.force"> {{model.force}} kN </span>
				</view>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">F = 0.25*πD²P * 10^(-3)</view>
				<view class="u-item-desc">式中：<br>
					D—井内管柱外径，mm；<br>
					P—井口压力的数值，MPa ；<br>
					F—井内压力对井内管柱最大上顶力的数值，kN。</view>

			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					f1: '',
					g1: '',
					force: ''
				},
				rules: {
					f1: [{
						required: true,
						message: '请输入井内压力对管柱的上顶力',
						trigger: 'blur'
					}],
					g1: [{
						required: true,
						message: '请输入管柱的自重',
						trigger: 'blur'
					}],
				},
				labelPosition: 'left',
				border: true,

			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						// 0.25*πD²P * 10^(-3)
						const D = parseFloat(this.model.f1);
						const P = parseFloat(this.model.g1);
						this.model.force = (P*(Math.PI*Math.pow(D/2,2))*0.001).toFixed(4);;
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>